<template>
  <div id="app">
    <el-container>
      <el-header>
        <div class="title">
          <img src="../assets/a.jpg" alt style="height:60px;width:60px">
          <p style="font-size:2em"><span style="color:green">黄</span>狗后台</p>
        </div>
        <el-row>
          <el-button type="danger" class="logout" @click="logout" title="好汉留步">告辞</el-button>
        </el-row>
      </el-header>

      <!-- 侧边栏 -->
      <el-container>
        <el-aside :width="isCollapse?'64px':'200px'">
          <!-- <div class="toggle-button" @click="toggleCollsapce">|||</div> -->
          <img
            src="../blue.jpg"
            alt
            style="width:100%;"
            class="toggle-button"
            @click="toggleCollsapce"
          >
          <el-menu
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            unique-opened
            :collapse="isCollapse"
            :collapse-transition="false"
            router
            :default-active="activePath"
            style="margin-top:-10px"
          >
            <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
              <template slot="title">
                <i :class="iconObj[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>
              <!-- 二级菜单 -->
              <el-menu-item
                @click="gaoliang('/'+ subitem.path)"
                :index="'/'+ subitem.path"
                v-for="subitem in item.children"
                :key="subitem.id"
              >
                <template slot="title">
                  <i class="el-icon-setting"></i>
                  <span>{{subitem.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>

        <!-- 右侧 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      menulist: [],
      iconObj: {
        "125": "el-icon-eleme",
        "103": "el-icon-user",
        "101": "el-icon-s-shop",
        "102": "el-icon-sell",
        "145": "el-icon-coin"
      },
      isCollapse: false,
      activePath: ""
      //  activePath:"/user",
    };
  },
  created() {
    // 一般喜欢写一个方法发ajax
    this.getMenuList();
    // this.activePath= window.sessionStorage.getItem("path")
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getMenuList() {
      let { data: res } = await this.$http.get("menus");
      // console.log(res);

      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.menulist = res.data;
      // console.log(res.data);
    },
    toggleCollsapce() {
      this.isCollapse = !this.isCollapse;
    },
    gaoliang(path) {
      this.activePath = path;
      // window.sessionStorage.setItem("path",path)
    }
  }
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
}
.el-header {
background-color:#169fe6
}
.el-aside {
  background: linear-gradient(
    135deg,
    black 0%,
    black 10%,
    white 10%,
    white 20%,
    black 20%,
    black 30%,
    white 30%,
    white 40%,
    black 40%,
    black 50%,
    white 50%,
    white 60%,
    black 60%,
    black 70%,
    white 70%,
    white 80%,
    black 80%,
    black 90%,
    white 90%,
    white 100%
  );


  .el-menu {
    border: none;
  }
}
.logout {
  position: absolute;
  right: 0;
  top: -45px;
  background-color: rgb(124, 87, 87) !important;
}

.title {
  display: flex;
  align-items: center;
  p {
    margin-left: 20px;
    color: #fff;
  }
}

.toggle-button {
  background-color: cornflowerblue;
  font-size: 10px;
  line-height: 24px;
  color: black;
  text-align: center;
  cursor: pointer;
  letter-spacing: 0.2rem;
}
</style>

